package cn.wolfcode.crm.util;

import org.springframework.util.StringUtils;

import java.lang.reflect.Method;

public class PermissionUtil {
    public static String getExpression(Method method){
        //使用Method的getDeclaringClass()方法来获得当前类名
        String simpleName = method.getDeclaringClass().getSimpleName();//DepartmentController
        //我们要把后缀Controller去掉,使用replace替换
        simpleName = simpleName.replace("Controller", "");
        //替换之后还要转换成小写,完成前部分department
        simpleName = StringUtils.uncapitalize(simpleName);
        //接下来获得方法名
        String methodName = method.getName();
        //然后进行权限表达式拼接
        String expression = simpleName + ":" + methodName;
        return expression;
    }
}
